<template>
  <div class="vip">
    <nav-bar></nav-bar>
    <div class="page-main clearfix">
      <div class="page-left">
        <div class="notice">
          <div class="notice-card">
            <div class="icon"></div>
            <div class="text1">低至约<span>0.2</span>元每天</div>
            <div class="text2">12个月会员</div>
          </div>
          <div class="notice-text">
            <div style="font-size:20px;margin-bottom:20px;">VIP特权</div>
            <div>
            支持全站优质资源无限下载
            所有资源下载无需语点
            包含会员用户所有权限
            </div>
          </div>
        </div>
      </div>
      <div class="page-right">
        <div class="title">选择开通类型：</div>
        <ul class="select">
          <li v-for="pg in packages" @click="changeTab(pg)" :style="pg.id == indexTab.id ? {borderColor: '#00A2EA'} : {borderColor: '#e5e6e7'}">
            <div class="money"><span class="num">{{pg.price}}</span><span>{{pg.month == 1 ? '元／月' : pg.month == 4 ? '元／季度' : pg.month == 6 ? '元／半年' : pg.month == 12 ? '元／年' : (' 元/' + pg.month + '月') }}</span></div>
            <div class="tips">每天下载次数{{pg.per_download}}次</div>
          </li>
        </ul>
        <div class="money-unit">
          <div v-if="indexTab">您已选择：{{indexTab.price}}{{indexTab.month == 1 ? '元／月' : indexTab.month == 4 ? '元／季度' : indexTab.month == 6 ? '元／半年' : indexTab.month == 12 ? '元／年' : (' 元/' + indexTab.month + '月') }}</div>
        </div>
        <div class="confirm-group clearfix">
          <span class="money">应付：{{indexTab.price}}元</span>
          <span class="tips">购买代表您同意<a style="color:#00A2EA">《晓语典vip服务协议》</a></span>
          <button class="common-btn" @click="handleOpen">立即开通</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { NavBar } from 'views/layout'
import { getVipList, joinVip } from 'api/vip'
export default {
  name: 'index',
  components: {
    NavBar
  },
  data() {
    return {
      packages: [],
      // packages: [
      //   {
      //     money: '30',
      //     unit: '元／季度',
      //     tips: '每天下载次数30次'
      //   }, {
      //     money: '60',
      //     unit: '元／半年',
      //     tips: '每天下载次数50次'
      //   }, {
      //     money: '100',
      //     unit: '元／年',
      //     tips: '不限下载次数'
      //   }
      // ],
      indexTab: ''
    }
  },
  created() {
    getVipList()
    .then(res => {
      console.log(res)
      this.packages = res
    })
    .catch(err => console.log(err))
  },
  methods: {
    changeTab(tab) {
      this.indexTab = tab
    },
    handleOpen() {
      joinVip({
        pid: this.indexTab.id
      })
      .then(res => {
        console.log(res)
        if (res.pay_url) {
          location.href = res.pay_url
        } else {
          this.$message({
            message: '提交成功',
            type: 'success'
          })
        }
      })
      .catch(err => {
        console.log(err)
        this.$message({
          message: '提交失败',
          type: 'warning'
        })
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.vip{
  .page-main{
    min-height: 400px;
    .page-left{
      float: left;
      width: 570px;
      margin-right: 50px;
      .notice{
        width: 100%;
        background-color: #f4f4f4;
        height: 257px;
        .notice-card{
          width: 257px;
          height: 257px;
          float: left;
          background-color: #F9A541;
          background: -webkit-gradient(linear,0 0,0 100%,from(#FAD961),to(#F76B1C));
          padding: 60px;
          text-align: center;
          .icon{
            width: 80px;
            height: 80px;
            display: inline-block;
            text-align: center;
            background-image: url('../../assets/common_images/vip-icon2.png');
            background-repeat: no-repeat;
            background-size: 80px;
          }
          .text1{
            color: #fff;
            text-align: center;
            >span{
              font-size: 20px;
            }
          }
          .text2{
            color: #fff;
            text-align: center;
            font-size: 12px;
          }
        }
        .notice-text{
          width: 313px;
          float: left;
          padding: 60px;
        }
      }
    }
    .page-right{
      float: left;
      width: 580px;
      .title{
        font-size: 20px;
        color: #ccc;
      }
      ul.select{
        padding: 20px 0;
        display: flex;
        justify-content: space-between;
        >li{
          width: 155px;
          height: 100px;
          border: 1px solid #e5e6e7;
          cursor: pointer;
          .money{
            line-height: 60px;
            text-align: center;
            font-size: 16px;
            color: #666;
            .num{
              color: #333;
              font-size: 20px;
              font-weight: bold;
            }
          }
          .tips{
            color: #999;
            text-align: center;
          }
        }
      }
      .money-unit{
        height: 48px;
        line-height: 48px;
        width: 100%;
      }
      .confirm-group{
        border: 1px solid #e5e6e7;
        height: 38px;
        padding-left: 10px;
        .money{
          font-size: 16px;
          line-height: 38px;
          font-weight: bold;
          vertical-align: middle;
        }
        .tips{
          font-size: 12px;
          line-height: 38px;
          color: #999;
          margin-left: 30px;
          vertical-align: middle;
        }
        .common-btn{
          float: right;
          margin-top: -1px;
          height: 38px;
          width: 160px;
          vertical-align: middle;
        }
      }
    }
  }
}
</style>